<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
        </style>
        <h2>Edit Sales Inquiry</h2>
        <h:form id="salesInquiryForm">
            <p:messages showDetail="true" />
            <p:growl id="growl" sticky="true"/>
            <p:panel id="panel1" header="Sales Inquiry">
                <h:panelGrid id="panelgrid1" columns="6" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                    <h:outputLabel style="font-weight: bold" value="#{slManagerBean.salesInquiry.salesLead.clientId}"/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Request For Quotation Id: "/>
                    <h:inputText id="sqNumber" value="#{slManagerBean.salesInquiry.rfiNumber}"/>

                    <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                    <h:outputText id="companyName" value="#{slManagerBean.salesInquiry.salesLead.companyName}" />
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Sales Inquiry Number: "/>
                    <h:inputText id="siNumber" value="#{slManagerBean.salesInquiry.siNumber}"/>

                    <h:outputLabel style="font-weight: bold" value="Currency: "/>
                    <h:selectOneRadio id="currency" required="true" requiredMessage="Please select one currency" value="#{slManagerBean.salesInquiry.currency}">
                        <f:selectItem itemLabel="SGD" itemValue="true"/>
                        <f:selectItem itemLabel="USD" itemValue="false"/>
                    </h:selectOneRadio>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Sales Inquiry Date: "/>
                    <h:outputText id="siDate" value="#{slManagerBean.salesInquiry.inquiryDate}">
                        <f:convertDateTime pattern="MMMM dd, yyyy"/>
                    </h:outputText>
                    
                </h:panelGrid>

                <p:panel id="panel2" header="Order Items">  
                     <p:dataTable id="ilTable" var="il" value="#{slManagerBean.salesInquiry.orderItems}" emptyMessage="No products selected">  
                            <p:column>  
                                <f:facet name="header">  
                                    Item Name
                                </f:facet>  
                                <h:outputText value="#{il.product.productType}" />  
                            </p:column>  
                            <p:column>  
                                <f:facet name="header">  
                                    Quantity
                                </f:facet>  
                                <h:outputText value="#{il.qtyOrderedCase}" />  
                            </p:column>  
                    </p:dataTable>
                    <br/>
                    <p:outputPanel layout="block" style="text-align:right">
                        <p:commandButton value="Update" update=":updateForm" oncomplete="updateIL.show()" image="ui-icon ui-icon-pencil" title="Update">
                        </p:commandButton>
                   </p:outputPanel>
               </p:panel>
                  <br/>
            </p:panel>                            
            <p:commandButton id="saveEditedSI" value="Save Changes" ajax="false" action="#{slManagerBean.recalculateSalesInquiry}" image="ui-icon ui-icon-disk" update="panel,display"/>
        <p:commandButton id="cancelEditSQ" value="Cancel Update" ajax="false" action="#{slManagerBean.cancelEditSI}" image="ui0icon ui-icon-close"/>
        </h:form>

 <p:dialog header="Update Item Lines" widgetVar="updateIL" modal="true" id="updateDlg" showEffect="fade" hideEffect="fade" resizable="false" width="800">
            <h:form id="updateForm">
                <p:fieldset legend="List of Products Ordered" style="font-weight: bold">
                    <p:dataTable var="newItemLine" value="#{slManagerBean.salesInquiry.orderItems}">
                        <p:column headerText="Product Type">
                            <h:outputLabel value="#{newItemLine.product.productType}"/>
                        </p:column>
                        <p:column headerText="Quantity Ordered Case">
                                <h:inputText value="#{newItemLine.qtyOrderedCase}"/>
                        </p:column>
                    </p:dataTable>
                </p:fieldset>
                <br/>           
                <p:outputPanel layout="block" style="text-align:right">
                    <p:commandButton value="Update" actionListener="#{slManagerBean.updateItemLine}" update="salesInquiryForm" oncomplete="updateIL.hide();" image="ui-icon ui-icon-check"/> 
                    <p:commandButton value="Cancel" onclick="updateIL.hide()" image="ui-icon ui-icon-close"/>  
                </p:outputPanel>
            </h:form>
  </p:dialog>
        
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>